<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>量体师管理</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>

<script type="text/javascript">
	function doAdd(){
		//alert("增加...");
		//$("input[name='sId']").val('-1');
		$('#addStandardWindow').form('clear');
		$('#addStandardWindow *').trigger('blur');// 离焦
		$('#addStandardWindow').window("open").window('setTitle', '添加员工');
		$("input[name='sId']").val('-1');
	}
	
	function getQueryParams(queryParams) {  
		var searchcontent = $('#searchcontent').val();
		var sc_phone = $('#sc_phone').val();
		var sc_ccode = $('#sc_ccode').val();
	     queryParams.username = searchcontent;  
	     queryParams.mobile = sc_phone;  
	     queryParams.countryCode = sc_ccode;  
	     return queryParams;  
	   
	 }  
	
	 //增加查询参数，重新加载表格  
    function reloadgrid() {  
  
        //查询参数直接添加在queryParams中      
        var queryParams = $('#grid').datagrid('options').queryParams;  
        getQueryParams(queryParams);  
        $('#grid').datagrid('options').queryParams = queryParams;  
        $("#grid").datagrid('load');  
    }  
	 
	function doSearch(){			
		reloadgrid();
	}
	
	function doEdit(){
		var rowData = $('#grid').datagrid('getSelected');  
        
        if (rowData == null) {  
            $.messager.alert("提示", "请选择要修改的行！", "info");  
        } else{
	        $("input[name='sId']").val(rowData.sId);
			$("input[name='sName']").val(rowData.sName);
			$("input[name='sLoginName']").val(rowData.sLoginName);
			$("input[name='sEmail']").val(rowData.sEmail);
			$("input[name='sPhone']").val(rowData.sPhone);
 			$('#sPwd').val(rowData.sPwd);
			$('#sStatus').combobox('setValue', rowData.sStatus);
	 		$('#dept').combobox('select', rowData.sDeptId);

			// 弹出窗口
			  
			$("#addStandardWindow").window('open').window('setTitle', '修改员工');
        } 
	}



	// 定义列
	var columns = [ [ {
		field : 'username',
		title : '用户名',
		width : 120,	
		/*align : 'center'*/
	},{
		field : 'mobile',
		title : '电话',
		width : 120,
		formatter:formatterTel
		/*align : 'center'*/
	},  {
		field : 'regdatetime',
		title : '注册时间',
		width : 120,
		/*align : 'center',*/
		formatter:formatterDate
	}, {
		field : 'devSys',
		title : '注册手机类型',
		width : 120,
		formatter:formatterDevSys
	}, {
		field : 'devModel',
		title : '手机型号',
		width : 120,
	}, {
		field : 'sysVersion',
		title : '系统版本',
		width : 120,
	}, {
		field : 'email',
		title : '邮箱',
		width : 120,
		/*align : 'center'*/
	},{
		field : 'countryCode',
		title : '国家代码',
		width : 120,
 		/*align : 'center'*/
	}/* ,  {
		field : 'countLogin',
		title : '总计登录次数',
		width : 80,
		align : 'center',
	},  {
		field : 'lLTime',
		title : '最近登录时间',
		width : 120,
		align : 'center',
		formatter:formatterDate
	} */] ];
	

	
	
	function formatterTel(value){
		return "<a target='blank' href='https://www.so.com/s?q="+value+"'>"+value+"</a>"
	} 
	

	

	$(function(){
		$('#add').click(doAdd);
		$('#edit').click(doEdit);
		$('#search').click(doSearch);
	});
	
	function formatterDate(value,row,index){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
	
	function formatterDevSys(value,row,index){
		if(value==1){
			return 'IOS';
		}else if(value==2){
			return 'Android';

		}
		
	}
	
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			singleSelect:true,
			striped : true,
			toolbar : '#tb',
			url : "${pageContext.request.contextPath}/page.userList.ashx",
			idField : 'sId',
			columns : columns,
			pageList: [1,10,20,30],
			pagination:true,
			/* onDblClickRow : doDblClickRow, */
			view:myview,
			emptyMsg:"<font size=5>暂无记录</font>"
			
		});
		
		//初始化员工窗口
		$('#addStandardWindow').window({
            title: '员工详情',
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
		//初始化员工窗口
		$('#FuQuanWindow').window({
            width: 400,
            modal: true,
            shadow: true,
            closed: true,
            height: 400,
            resizable:false
            
        });
		
		//提交表单
		$('#save').click(function(){
				// 校验
				if($('#sform').form('validate')){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.saveOrUpdateKuguan.ashx", params , function(data){
						if(data == "success"){
							// 成功
							$.messager.alert('消息','操作成功 ','info');
							// 关闭窗口
							$('#addStandardWindow').window('close');
							// 清除表单数据
							$("input[name='sId']").val('');
							$('#addStandardWindow').form('clear');
							$('#addStandardWindow *').trigger('blur');// 离焦
							
							// 刷新表格数据 
							$('#grid').datagrid('reload');
						}else if(data=="conflict"){
							$.messager.alert('消息','登录名已经被占用！ ','info');
						}else{
							$.messager.alert('消息','操作失败 ','info');
						}
							
					});
				}
				
			});	
		
		
	});
	
	
	
	var myview = $.extend({},$.fn.datagrid.defaults.view,{
		onAfterRender:function(target){
			$.fn.datagrid.defaults.view.onAfterRender.call(this,target);
			var opts = $(target).datagrid('options');
			var vc = $(target).datagrid('getPanel').children('div.datagrid-view');
			vc.children('div.datagrid-empty').remove();
			if (!$(target).datagrid('getRows').length){
				var d = $('<div class="datagrid-empty"></div>').html(opts.emptyMsg || 'no records').appendTo(vc);
				d.css({
					position:'absolute',
					left:0,
					top:50,
					width:'100%',
					textAlign:'center'
				});
			}
		}
	});
	$.extend($.fn.validatebox.defaults.rules, {   
	    //验证汉字   
	    CHS: {   
	        validator: function (value) {   
	            return /^[\u0391-\uFFE5]+$/.test(value);   
	        },   
	        message: '只能输入汉字'  
	    },   
	    //移动手机号码验证   
	    mobile: {//value值为文本框中的值   
	        validator: function (value) {   
	            var reg = /^1[3|4|5|7|8|9]\d{9}$/;   
	            return reg.test(value);   
	        },   
	        message: '输入手机号码格式不准确.'  
	    },   
	    //国内邮编验证   
	    zipcode: {   
	        validator: function (value) {   
	            var reg = /^[1-9]\d{5}$/;   
	            return reg.test(value);   
	        },   
	        message: '邮编必须是非0开始的6位数字.'  
	    },   
	    //用户账号验证(只能包括 _ 数字 字母)    
	    account: {//param的值为[]中值   
	        validator: function (value, param) {   
	            if (value.length < param[0] || value.length > param[1]) {   
	                $.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围';   
	                return false;   
	            } else {   
	                if (!/^[\w]+$/.test(value)) {   
	                    $.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.';   
	                    return false;   
	                } else {   
	                    return true;   
	                }   
	            }   
	        }, message: ''  
	    }   
	})
	

	
		
</script>	
</head>
<body class="easyui-layout" >
	<div region="center">
	
		<table id="grid">
		
		</table>
	</div>
	
	
	
		<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
	
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户名: <input id="searchcontent" class="easyui-textbox" style="width:80px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;手机号: <input id="sc_phone" class="easyui-textbox" style="width:80px">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;国家代码: <input id="sc_ccode" class="easyui-textbox" style="width:80px">
			<a href="#"  id="search" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
		
		</div>
	</div>
	
	
	
	
	
</body>
</html>